#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
ZetCode PyQt5 tutorial 

This program shows a confirmation 
message box when we click on the close
button of the application window. 

author: Jan Bodnar
website: zetcode.com 
last edited: January 2015
"""

import sys
from PyQt5.QtWidgets import QWidget, QMessageBox, QApplication, QPushButton, QToolTip
from PyQt5.QtCore import QCoreApplication
from PyQt5.QtGui import QFont 


def pop_message_box():
    reply = QMessageBox.question(None, 'Message Box', "This is a Message Box", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
    #if reply == QMessageBox.Yes:
    #else:

class Example(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.initUI()
        
        
    def initUI(self):               

        #这种静态的方法设置一个用于显示工具提示的字体。我们使用10px滑体字体。
        QToolTip.setFont(QFont('SansSerif', 10))

        qbtn = QPushButton('pop message box', self)
        qbtn.setToolTip('push it while pop a <b>Message Box</b>')
        qbtn.clicked.connect(pop_message_box)
        qbtn.resize(qbtn.sizeHint())
        qbtn.move(350, 250)  

        self.setGeometry(300, 300, 500, 300)        
        self.setWindowTitle('Message box')    
        self.show()
        
        
    def closeEvent(self, event):
        
        reply = QMessageBox.question(self, 'Message', "Are you sure to quit?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)

        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()        
        
        
if __name__ == '__main__':
    
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

